#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_STRING_LENGTH 100
#define MAX_APS 1000 // Assuming a maximum of 1000 access points

struct WirelessNetwork {
    int id;
    char name[MAX_STRING_LENGTH];
    char mac[MAX_STRING_LENGTH];
    char security[MAX_STRING_LENGTH];
    int signal_strength;
    char standards[MAX_STRING_LENGTH];
    char location[MAX_STRING_LENGTH];
    char internet_access[MAX_STRING_LENGTH];
    char is_active[MAX_STRING_LENGTH];
};

// 遍历结构体数组的方法
void print_struct(struct WirelessNetwork *APs, int n) {
    for (int i = 0; i < n; i++) {
        printf("%d %s %s %s %d %s %s %s %s\n", APs[i].id, APs[i].name, APs[i].mac, APs[i].security,
               APs[i].signal_strength, APs[i].standards, APs[i].location, APs[i].internet_access,
               APs[i].is_active);
        printf("%d %s\n", APs[i].id, APs[i].name);
    }
}

int main() {
    FILE *fp = fopen("recourse/APlist.txt", "r");
    struct WirelessNetwork APs[MAX_APS];
    char line[MAX_STRING_LENGTH * 5];

    int i = 0;
    if(fp!= NULL) {
        while (fgets(line, sizeof(line), fp)) {
            char *col;
            char *temp = strdup(line);
//            printf("%d\n",++count);

            col = strtok(temp, "\t\n");
//            int j = 0;
//            while (*col != '\n')
//            {
//                printf("%c", *(col+ (j++)));
//            }
            while (col != NULL) {
                printf("%s\n", col);
                col = strtok(NULL, "\t\n"); // Changed delimiter to '\t' for tab
            }
            ++i;
            printf("-----------------------------------------------------------------\n");
            free(temp);
        }
        fclose(fp);
    } else{
        printf("Error opening file!\n");
    }

//    print_struct(APs, i);


    return 0;
}